package com.zzedu.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zzedu.common.annotation.Log;
import com.zzedu.common.core.controller.BaseController;
import com.zzedu.common.core.domain.AjaxResult;
import com.zzedu.common.core.page.TableDataInfo;
import com.zzedu.common.enums.BusinessType;
import com.zzedu.common.utils.ServletUtils;
import com.zzedu.common.utils.poi.ExcelUtil;
import com.zzedu.domain.ZzAppDevice;
import com.zzedu.dto.ZzAppDeviceDTO;
import com.zzedu.service.IZzAppDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 大屏管理Controller
 *
 * @author Mr.Wang
 * @date 2025-06-02
 */
@RestController
@RequestMapping("/school/device")
public class ZzAppDeviceController extends BaseController {
    @Autowired
    private IZzAppDeviceService zzAppDeviceService;

    /**
     * 查询大屏管理列表
     */
    @PreAuthorize("@permission.hasAnyPermissions('school:device:query')")
    @RequestMapping("/list")
    public TableDataInfo list(@RequestBody ZzAppDeviceDTO zzAppDevice) {
        IPage<ZzAppDevice> page = zzAppDeviceService.page(zzAppDevice.getPageDTO(), zzAppDeviceService.buildQuery(zzAppDevice));
        return getDataTable(page, zzAppDeviceService.convertVO(page.getRecords()));
    }

    /**
     * 导出大屏管理列表
     */
    @PreAuthorize("@permission.hasAnyPermissions('school:device:export')")
    @Log(title = "大屏管理", businessType = BusinessType.EXPORT)
    @RequestMapping("/export")
    public void export(ZzAppDeviceDTO zzAppDevice) {
        List<ZzAppDevice> list = zzAppDeviceService.list(zzAppDeviceService.buildQuery(zzAppDevice));
        ExcelUtil<ZzAppDevice> util = new ExcelUtil<ZzAppDevice>(ZzAppDevice.class);



        util.exportExcel(ServletUtils.getResponse(), list, "大屏管理数据");
    }


    /**
     * 新增保存大屏管理
     */
    @PreAuthorize("@permission.hasAnyPermissions('school:device:add')")
    @Log(title = "大屏管理", businessType = BusinessType.INSERT)
    @RequestMapping("/add")
    public AjaxResult addSave(@Validated @RequestBody ZzAppDevice zzAppDevice) {
        return toAjax(zzAppDeviceService.save(zzAppDevice));
    }


    /**
     * 获取大屏管理详细信息
     */
    @PreAuthorize("@permission.hasAnyPermissions('school:device:query')")
    @RequestMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(zzAppDeviceService.getById(id));
    }


    /**
     * 修改保存大屏管理
     */
    @PreAuthorize("@permission.hasAnyPermissions('school:device:edit')")
    @Log(title = "大屏管理", businessType = BusinessType.UPDATE)
    @RequestMapping("/edit")
    public AjaxResult editSave(@Validated @RequestBody ZzAppDevice zzAppDevice) {
        return toAjax(zzAppDeviceService.updateById(zzAppDevice));
    }

    /**
     * 删除大屏管理
     */
    @PreAuthorize("@permission.hasAnyPermissions('school:device:remove')")
    @Log(title = "大屏管理", businessType = BusinessType.DELETE)
    @RequestMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids) {
        return toAjax(zzAppDeviceService.removeBatchByIds(ids));
    }
}
